package common.types;

import java.util.Date;

public class StatisticsEntry implements Comparable<StatisticsEntry> {

	private String guessCharacterName;
	private String actualCharacterName;
	private boolean isCorrect;
	private Date timeStamp;
	
	public StatisticsEntry(String guessCharacterName, String actualCharacterName, boolean isCorrect, Date timeStamp) {
		this.guessCharacterName = guessCharacterName;
		this.actualCharacterName = actualCharacterName;
		this.isCorrect = isCorrect;
		this.timeStamp = timeStamp;
	}
	
	public StatisticsEntry() {}

	public String getGuessCharacterName() {
		return guessCharacterName;
	}
	
	public void setGuessCharacterName(String guessCharacterName) {
		this.guessCharacterName = guessCharacterName;
	}
	
	public String getActualCharacterName() {
		return actualCharacterName;
	}
	
	public void setActualCharacterName(String actualCharacterName) {
		this.actualCharacterName = actualCharacterName;
	}
	
	public Date getTimeStamp() {
		return timeStamp;
	}
	
	public void setTimeStamp(Date timeStamp) {
		this.timeStamp = timeStamp;
	}

	public void setCorrect(boolean isCorrect) {
		this.isCorrect = isCorrect;
	}

	public boolean isCorrect() {
		return isCorrect;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof StatisticsEntry) {
			StatisticsEntry entry = (StatisticsEntry) obj;
			return 	guessCharacterName.equals(entry.getGuessCharacterName()) &&
					actualCharacterName.equals(entry.getActualCharacterName()) &&
					isCorrect == entry.isCorrect &&
					timeStamp.equals(entry.getTimeStamp());
		}
		return false;
	}

	
	
	@Override
	public int compareTo(StatisticsEntry entry) {
		int compareTimeStamps = timeStamp.compareTo(entry.getTimeStamp());
		if (compareTimeStamps!=0){
			return compareTimeStamps;
		}
		else {
			int compareGuessCharacterName = guessCharacterName.compareTo(entry.getGuessCharacterName());
			if (compareGuessCharacterName!=0){
				return compareGuessCharacterName;
			}
			else {
				int compareActualCharacterName = actualCharacterName.compareTo(entry.getActualCharacterName());
				if (compareActualCharacterName!=0){
					return compareActualCharacterName;
				}
				else {
					if (isCorrect==entry.isCorrect()){return 0;}
					else if (isCorrect==true && entry.isCorrect()==false){return 1;}
					else if (isCorrect==false && entry.isCorrect()==true){return -1;}
				}
			}
		}
		return -1;
	}
}
